home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 26
/
Cream of the Crop 26.iso
/
program
/
qlib205.zip
/
QLIB.ZIP
/
C
/
IASM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-07-09
|
3KB
|
103 lines
//#define DEBUG
// Inline ASM Convert v1.01 32bit
// By:Peter Quiring (source copied from PASM)
// Please note : iASM was originally thought up by Cameron Bushartd
/*/
For WATCOM C/C++
Notes:
-after creating this I've found some minor bugs in PASM since I copied the
source from PASM for this little util.
-DO NOT use local variables inside ASM blocks since they may be in
registers or something. Just preserve everything and use only
global data. (if you need to use local stuff or parameters pushed to
a func you'll need to use the proper Watcom ASM {} style which
sucks and is a pAin in the ass)
Advantages:
-allow "asm {}" blocks in Watcom C files
-allow single asm statements, eg: asm mov ax,3
-you can keep labels inside the {} (watcom only and BCv5.0)
-ALL output always goes to c.tmp (unlike PASM which goes to asm.tmp & _str_.tmp)
Disadvantages:
-iASM looks for 'ASM ' at the begining of ANY line! So if a comment starts
with asm in a line it will cause errors. It's too much to seek out commment
blocks and such (considering they could be in strings and it's just too much)
but this should hardly even happen.
/*/
#include <qlib.h>
#include <string.h>
#include <dos.h>
#include <stdlib.h>
#include <stdio.h>
#define mh 64 //max handles (the incs)
#define bufsiz 32*1024 //buffer size
byte buf[256]; //current line
byte str[256];
byte *bufo1;
word bufp1;
byte * bufin[mh];
word bufip[mh]; //buffer pos
word bufis[mh]; //buffer size left (bufsiz-pos)
word bufln[mh]; //current line #
byte buffn[mh][80]; //file names
word cnum; //current asm block number
int ho1; // handle out for large C file (c.tmp)
byte ho1on; //handle above has been created
int h; // current file handle (in)
int hs[mh]; // handles (all kept in place) (requires a lot of handles in config.sys)
byte ch; // current handle # (within hs and all other things)
byte EOFF[mh]; // flag (indicates that we have hit EOF)
byte *file; //pts to filename to open
byte enter[3]={13,10,0};
byte *inc; //INCLUDE name from enviroment
word incsiz; //size of inc string
byte t2[80];
byte first;
byte obuf[80];
//Protos
void flush(void);
void errorf(byte *s);
void error(byte *s);
void readln(void);
void prefile(void);
void out(byte*);
void asm_pre(void);
void asm_done(void);
void out_asm(byte *s);
void prefile(void);
void out(byte *str);
void setup(void);
void dofile(void);
//#define DEBUG
#define IASM
#include "err-i.h" //these are shared between iASM and PASM
#include "readln.h"
#include "iasm.h"
#include "do.h"
void main(void) {
byte a;
printf("Watcom C \"inline ASM converter\" v1.01 32bit (by : Peter Quiring)\n");
ho1on=0;
bufp1=0;
bufo1=(void*)malloc(bufsiz);
if ( (dword)bufo1==ERROR) error("Out of RAM");
for(a=0;a<mh;a++) bufin[a]=0;
if (_argc!=2) error("Usage: iASM 'file.c'");
file=_argv[1];
ch=255;
cnum=0;
setup();
dofile();
flush();
printf("Complete!\n\n");
exit(0);
}